const {Sequelize, DataTypes} = require('sequelize');
const { _Mysql } = require('../appConfig')

const sequelize = new Sequelize(_Mysql.db, _Mysql.acount, _Mysql.pwd, {
    host: _Mysql.host,
    port:_Mysql.port,
    dialect: 'mysql',
    pool: {
        max: 5, //连接池最大连接数量
        min: 0, //最小连接数量
        idle: 20000, //如果一个线程 20秒内没有被使用过的话，就释放
    },
})


if(_Mysql.look){
    sequelize.authenticate()  
  .then(() => {  
    console.log('Connection has been established successfully.');  
  })  
  .catch(err => {  
    console.error('Unable to connect to the database:', err);  
  });
}

module.exports = {
    sequelize: sequelize, DataTypes: DataTypes
}